package newsSystem.Test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SubscriptionPanel extends JPanel {
    private JTextField subscriptionField;
    private JTextField monthField;
    private JTextField dateField;

    public SubscriptionPanel() {
        setLayout(new GridLayout(4, 2));

        JLabel subscriptionLabel = new JLabel("Subscription Score:");
        JLabel monthLabel = new JLabel("Subscription Month:");
        JLabel dateLabel = new JLabel("Order Date:");

        subscriptionField = new JTextField();
        monthField = new JTextField();
        dateField = new JTextField();

        add(subscriptionLabel);
        add(subscriptionField);
        add(monthLabel);
        add(monthField);
        add(dateLabel);
        add(dateField);

        JButton subscribeButton = new JButton("Subscribe");
        add(subscribeButton);

        JButton cancelButton = new JButton("Cancel");
        add(cancelButton);
        subscribeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // 处理订阅逻辑
                String subscription = subscriptionField.getText();
                String month = monthField.getText();
                String date = dateField.getText();

                // 在这里添加订阅的逻辑，可以根据获取到的订阅信息执行相应操作
                System.out.println("订阅信息：");
                System.out.println("订阅分数：" + subscription);
                System.out.println("订阅月份：" + month);
                System.out.println("订单日期：" + date);

                // 清空输入框
                subscriptionField.setText("");
                monthField.setText("");
                dateField.setText("");
            }
        });

        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // 清空输入框
                subscriptionField.setText("");
                monthField.setText("");
                dateField.setText("");
            }
        });

    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("用户订阅");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null); // 居中显示
        frame.setBounds(10, 10, 100, 100);
        SubscriptionPanel panel = new SubscriptionPanel();

        frame.getContentPane().add(panel);

        frame.pack();
        frame.setVisible(true);
    }
}
